package com.ytoglobal.overseas.address.platform.model;

import com.alibaba.fastjson.annotation.JSONField;
import lombok.Data;

import java.util.Date;

@Data
public class ResponseEntity<T> {

    /**
     * 状态
     **/
    @JSONField
    private int status;

    /**
     * 内容
     **/
    @JSONField
    private String message;

    /**
     * 内容
     **/
    @JSONField
    private T data;

    /**
     * 时间戳
     **/
    @JSONField
    private Date timestamp = new Date();

    private ResponseEntity() {
    }

    private ResponseEntity(Integer status, String message, T data) {
        this.status = status;
        this.message = message;
        this.data = data;
    }

    public static <T> ResponseEntity<T> ok() {
        return new ResponseEntity<>(200, "OK", null);
    }

    public static <T> ResponseEntity<T> ok(T data) {
        return new ResponseEntity<>(200, "OK", data);
    }

    public static <T> ResponseEntity<T> fail() {
        return new ResponseEntity<>(500, "Internal Server Error", null);
    }

    public static <T> ResponseEntity<T> fail(Integer status, String message) {
        return new ResponseEntity<>(status, message, null);
    }

    public static <T> ResponseEntity<T> fail(Integer status, String message, T data) {
        return new ResponseEntity<>(status, message, data);
    }

    public static <T> ResponseEntity<T> build(Integer status, String message, T data) {
        return new ResponseEntity<>(status, message, data);
    }

}
